/**
 * @author klv
 */
if (typeof(QSAPI_PROTOCOL) == "undefined") {
    QSAPI_PROTOCOL = "http://";
}
if(typeof(STATIC_VAR)=="undefined"){
    var STATIC_VAR={marketIndexSessionExists:false,marketsFirstLoad:false};
}
function SiteBuilder_firstLoadLoginPage(){
    if (STATIC_VAR.marketsFirstLoad == false) {
        $(document.body).append("<iframe style='display:none' onreadystatechange='STATIC_VAR.marketIndexSessionExists=true' onload='STATIC_VAR.marketIndexSessionExists=true' src='" + QS_PROTOCOL + "awrd.morningstar.com/advisor/login/instlgn.asp?instid=SBDEMO&login=Support_1&pwd=Support_1'></iframe>");
        STATIC_VAR.marketsFirstLoad = true;
    }
}
String.format = function(str) {
    if(typeof(str)!="string")return "";
    if (arguments.length <= 1)
        return str;
    var lastIndex = arguments.length - 2;
    for (var i = 0; i <= lastIndex; i++)
        str = str.replace(new RegExp("\\{" + i + "\\}", "img"), arguments[i + 1]);
    return str;
};
var api_common_openwindow={
	getHostAddress:function(){
        return String.format("{0}//{1}{2}",window.location.protocol,window.location.host,window.location.pathname);
    },
    getLocationArg:function(){
        var urlCfg={};
        var __url = window.location.search;
        if (__url != "" && __url.length > 0) {
            __url = __url.substr(__url.indexOf("?")+1);
        }
        var carr = __url.split("&");
        for (var i = 0; i < carr.length; i++) {
            var item = carr[i].split("=");
            urlCfg[$.trim(item[0])] = $.trim(item[1]);
        }
        return urlCfg;
    },
	genURL:function(data){
		return String.format("{0}?{1}",api_common_openwindow.getHostAddress(),$.param(data));

	},
	genExternalURL:function(domain,data){
        return String.format("{0}?{1}",domain,$.param(data));

    },
    openWindow:function(URL,title){
        window.open(URL,title, "toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=1000,height=800");
    }
}
